<!--

    Copyright © 2016-2024 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="tb-form-panel stroked" [formGroup]="mappingFormGroup">
  <div class="tb-form-panel-title" [class.tb-required]="required" translate>device.device</div>
  <div class="tb-form-table no-padding no-gap">
    <div class="tb-form-table-header">
      <div class="tb-form-table-header-cell table-name-column" translate>gateway.device-info.entity-field</div>
      <div *ngIf="useSource" class="tb-form-table-header-cell table-column" translate>gateway.device-info.source</div>
      <div class="tb-form-table-header-cell table-column" translate>
        gateway.device-info.expression
      </div>
    </div>
    <div class="tb-form-table-body no-gap">
      <div class="tb-form-table-row tb-form-row no-border same-padding top-same-padding"
           [class.bottom-same-padding]="deviceInfoType !== DeviceInfoType.FULL">
        <div class="fixed-title-width tb-required" translate>gateway.device-info.name</div>
        <div class="tb-flex no-gap raw-value-option" *ngIf="useSource">
          <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
            <mat-select formControlName="deviceNameExpressionSource">
              <mat-option *ngFor="let type of sourceTypes" [value]="type">
                {{ SourceTypeTranslationsMap.get(type) | translate }}
              </mat-option>
            </mat-select>
          </mat-form-field>
        </div>
        <div class="tb-form-table-row-cell tb-flex no-gap">
          <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
            <input matInput name="value" formControlName="deviceNameExpression" placeholder="{{ 'gateway.set' | translate }}"/>
            <mat-icon matSuffix
                      matTooltipPosition="above"
                      matTooltipClass="tb-error-tooltip"
                      [matTooltip]="('gateway.device-info.device-name-expression-required') | translate"
                      *ngIf="mappingFormGroup.get('deviceNameExpression').hasError('required') &&
                             mappingFormGroup.get('deviceNameExpression').touched"
                      class="tb-error">
              warning
            </mat-icon>
            <div *ngIf="'name-field' | getGatewayHelpLink : mappingFormGroup.get('deviceNameExpressionSource').value : sourceTypes"
                 matSuffix
                 class="see-example"
                 [tb-help-popup]="'name-field' | getGatewayHelpLink : mappingFormGroup.get('deviceNameExpressionSource').value : sourceTypes"
                 tb-help-popup-placement="left"
                 [tb-help-popup-style]="{maxWidth: '970px'}">
            </div>
          </mat-form-field>
        </div>
      </div>
      <div class="tb-form-table-row tb-form-row no-border same-padding bottom-same-padding"
           *ngIf="deviceInfoType === DeviceInfoType.FULL">
        <div class="fixed-title-width tb-required" translate>gateway.device-info.profile-name</div>
        <div class="tb-flex no-gap raw-value-option" *ngIf="useSource">
          <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
            <mat-select formControlName="deviceProfileExpressionSource">
              <mat-option *ngFor="let type of sourceTypes" [value]="type">
                {{ SourceTypeTranslationsMap.get(type) | translate }}
              </mat-option>
            </mat-select>
          </mat-form-field>
        </div>
        <div class="tb-form-table-row-cell tb-flex no-gap">
          <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
            <input matInput name="value" formControlName="deviceProfileExpression" placeholder="{{ 'gateway.set' | translate }}"/>
            <mat-icon matSuffix
                      matTooltipPosition="above"
                      matTooltipClass="tb-error-tooltip"
                      [matTooltip]="('gateway.device-info.device-profile-expression-required') | translate"
                      *ngIf="mappingFormGroup.get('deviceProfileExpression').hasError('required') &&
                             mappingFormGroup.get('deviceProfileExpression').touched"
                      class="tb-error">
              warning
            </mat-icon>
            <div *ngIf="'profile-name' | getGatewayHelpLink: mappingFormGroup.get('deviceProfileExpressionSource').value : sourceTypes"
                 matSuffix
                 class="see-example"
                 [tb-help-popup]="'profile-name' | getGatewayHelpLink: mappingFormGroup.get('deviceProfileExpressionSource').value : sourceTypes"
                 tb-help-popup-placement="left"
                 [tb-help-popup-style]="{maxWidth: '970px'}">
            </div>
          </mat-form-field>
        </div>
      </div>
    </div>
  </div>
</div>
